/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.hiof.moraa.server.service;

import com.hiof.moraa.server.dao.PassTargetDAO;
import com.hiof.moraa.server.service.model.PassTargetFeed;
import com.hiof.moraa.server.service.model.TypeOfAttendant;
import java.sql.Timestamp;

/**
 *
 * @author Bergy
 */
public class CheckPassTargetService {

    PassTargetDAO dao;
    MessageDeliveryService messageDeliveryService;

    public void setDao(PassTargetDAO dao) {
        this.dao = dao;
    }

    public void setMessageDeliveryService(MessageDeliveryService messageDeliveryService) {
        this.messageDeliveryService = messageDeliveryService;
    }

    public void checkPassTarget(int userId, int athleteId, double lat, double lng, double high) {
        int targetId = isPassTarget(lat, lng, high);
        if (targetId > 0) {
            PassTargetFeed passTargetFeed = dao.insertPassTargetData(targetId, athleteId, -1, new Timestamp(new java.util.Date().getTime()));
            messageDeliveryService.deliveryTargetMessage(userId, TypeOfAttendant.ATHLETE, athleteId, passTargetFeed);
        }
    }

    /**
     * check the location pass target or not
     * @param lat
     * @param lng
     * @param high
     * @return: id of target (-1) if fail
     */
    public int isPassTarget(double lat, double lng, double high) {
        //TODO: fetch all target from database and check whether location near target or not
        return -1;
    }
}
